package cate.common.table.activity.specialtraining.shop;

import cate.common.table.ERow;
import cate.common.table.XSSFRowWrap;
import easy.java.dev.note.NoteClass;
import easy.java.dev.note.NoteField;

@NoteClass(value = "特训活动-商品 Row")
public class SpecialTrainingShopRow extends ERow {
    @NoteField(value = "天数")
    public int day;
    @NoteField(value = "分组")
    public int group;
    @NoteField(value = "购买类型")
    public int buyType;
    @NoteField(value = "奖励")
    public String rewardStr;
    @NoteField(value = "价格")
    public String costStr;
    @NoteField(value = "充值项ID")
    public int payId;
    @NoteField(value = "限购次数")
    public int buyLimit;
    @NoteField(value = "vip等级")
    public int needVip;

    @Override
    public void parse(XSSFRowWrap xrw) {
        super.parse(xrw);
        id = xrw.getInteger("ID");
        day = xrw.getInteger("天数");
        group = xrw.getInteger("分组");
        buyType = xrw.getInteger("购买类型");
        rewardStr = xrw.getString("奖励");
        costStr = xrw.getString("价格");
        payId = xrw.getInteger("充值项ID", 0);
        buyLimit = xrw.getInteger("限购次数");
        needVip = xrw.getInteger("vip等级");
    }

    @Override
    public void decode() {
        super.decode();
        if (rewardStr == null || rewardStr.isEmpty()) {
            getContext().warningOnSheetLoading(parent.parent.getFileName(),
                    parent.getSheetName(),
                    "ID=" + id + " 未配置商品!");
        }
        switch (buyType) {
            case SpecialTrainingShopSheet.ST_BUY_TYPE_FREE: {
                if (costStr != null && !costStr.isEmpty()) {
                    getContext().warningOnSheetLoading(parent.parent.getFileName(),
                            parent.getSheetName(),
                            "ID=" + id + " 购买类型 免费 但是配置了物品消耗!");
                }
                if (payId > 0) {
                    getContext().warningOnSheetLoading(parent.parent.getFileName(),
                            parent.getSheetName(),
                            "ID=" + id + " 购买类型 免费 但是配置了充值项ID!");
                }
            }
            break;
            case SpecialTrainingShopSheet.ST_BUY_TYPE_ITEMS: {
                if (costStr == null || costStr.isEmpty()) {
                    getContext().warningOnSheetLoading(parent.parent.getFileName(),
                            parent.getSheetName(),
                            "ID=" + id + " 购买类型 消耗道具 但是没有配置物品消耗!");
                }
                if (payId > 0) {
                    getContext().warningOnSheetLoading(parent.parent.getFileName(),
                            parent.getSheetName(),
                            "ID=" + id + " 购买类型 消耗道具 但是配置了充值项ID!");
                }
            }
            break;
            case SpecialTrainingShopSheet.ST_BUY_TYPE_PAY: {
                if (costStr != null && !costStr.isEmpty()) {
                    getContext().warningOnSheetLoading(parent.parent.getFileName(),
                            parent.getSheetName(),
                            "ID=" + id + " 购买类型 支付 但是配置了物品消耗!");
                }
                if (payId == 0) {
                    getContext().warningOnSheetLoading(parent.parent.getFileName(),
                            parent.getSheetName(),
                            "ID=" + id + " 购买类型 支付 但是没有配置充值项ID!");
                }
            }
            break;
            default: {
                getContext().warningOnSheetLoading(parent.parent.getFileName(),
                        parent.getSheetName(),
                        "ID=" + id + " 配置了错误的购买类型!");
            }
            break;
        }
    }
}
